<template>
  <div class="past-medical-history">
    <h2>{{ $t('medicalHistory.title') }}</h2>
    
    <div class="history-list">
      <!-- 病史记录列表 -->
      <div 
        v-for="(history, index) in historyData" 
        :key="index" 
        class="history-item"
      >
        <div class="history-header">
          <span class="history-label">{{ $t('medicalHistory.historyLabel', { index: index + 1 }) }}</span>
          <span class="history-time">{{ formatDateTime(history.date) }}</span>
        </div>
        <div class="history-content">{{ history.content }}</div>
        <button 
          @click="deleteHistory(index)" 
          class="delete-btn"
        >
          {{ $t('medicalHistory.delete') }}
        </button>
      </div>

      <!-- 添加病史的表单 -->
      <div class="history-input-form">
        <input 
          type="text" 
          v-model="newHistory.content" 
          :placeholder="$t('medicalHistory.inputPlaceholder')"
          class="history-input-field"
          @keyup.enter="addHistory"
        />
        <button @click="addHistory" class="add-btn">
          {{ $t('medicalHistory.add') }}
        </button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      newHistory: {
        content: '',
      },
      historyData: [
        { 
          content: '糖尿病', 
          date: new Date(2023, 2, 15, 14, 30) 
        },
        { 
          content: '高血压', 
          date: new Date(2023, 2, 16, 9, 15) 
        },
        { 
          content: '', 
          date: new Date() 
        }
      ]
    };
  },
  methods: {
    addHistory() {
      if (!this.newHistory.content.trim()) return;
      
      const newRecord = {
        content: this.newHistory.content,
        date: new Date()
      };
      
      this.historyData.unshift(newRecord);
      this.newHistory.content = '';
    },
    deleteHistory(index) {
      this.historyData.splice(index, 1);
    },
    formatDateTime(date) {
      if (!date) return '';
      const d = new Date(date);
      return `${d.getFullYear()}-${(d.getMonth()+1).toString().padStart(2, '0')}-${d.getDate().toString().padStart(2, '0')} ${d.getHours().toString().padStart(2, '0')}:${d.getMinutes().toString().padStart(2, '0')}`;
    }
  }
};
</script>

<style scoped>
.past-medical-history {
  max-width: 800px;
  margin: 30px auto;
  padding: 30px;
  background-color: #f5f9ff;
  border-radius: 12px;
  font-family: 'Helvetica Neue', Arial, sans-serif;
}

h2 {
  text-align: center;
  color: #2c3e50;
  margin-bottom: 25px;
  font-size: 22px;
  font-weight: 600;
}

.history-list {
  background-color: #fff;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

.history-item {
  position: relative;
  padding: 15px;
  margin-bottom: 15px;
  background-color: #f8fafc;
  border-radius: 6px;
  border: 1px solid #e0e6ed;
}

.history-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
}

.history-label {
  font-weight: 600;
  color: #3a5169;
  font-size: 15px;
}

.history-time {
  font-size: 13px;
  color: #718096;
}

.history-content {
  font-size: 15px;
  color: #2d3748;
  margin: 10px 0;
  padding: 8px 0;
}

.delete-btn {
  position: absolute;
  right: 15px;
  bottom: 15px;
  background-color: #ff6b6b;
  color: white;
  border: none;
  border-radius: 4px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.3s;
}

.delete-btn:hover {
  background-color: #ff5252;
}

.history-input-form {
  display: flex;
  gap: 10px;
  margin-top: 30px;
}

.history-input-field {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid #e0e6ed;
  border-radius: 6px;
  font-size: 15px;
}

.add-btn {
  background-color: #2196F3;
  color: white;
  border: none;
  border-radius: 6px;
  padding: 12px 20px;
  cursor: pointer;
  font-size: 15px;
  transition: all 0.3s;
}

.add-btn:hover {
  background-color: #0b7dda;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .past-medical-history {
    padding: 20px;
  }
  
  .history-input-form {
    flex-direction: column;
  }
  
  .add-btn {
    width: 100%;
  }
}
</style>